package cn.monkey.transport.netty.duplex;

import cn.monkey.transport.core.Exchange;
import cn.monkey.transport.core.ExchangeFactory;
import cn.monkey.transport.netty.NettyExchange;
import cn.monkey.transport.netty.NettyExchangeFactory;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

public class SimpleDuplexExchangeFactory<C> extends AbstractDuplexExchangeFactory<C, NettyExchange, Exchange, DuplexExchange> {
    protected Scheduler scheduler = Schedulers.newSingle("duplexExchange");

    public SimpleDuplexExchangeFactory(NettyExchangeFactory<NettyExchange> nettyExchangeFactory, ExchangeFactory<C, Exchange> exchangeFactory) {
        super(nettyExchangeFactory, exchangeFactory);
    }

    public void setScheduler(Scheduler scheduler) {
        this.scheduler = scheduler;
    }

    @Override
    protected DuplexExchange newExchange(NettyExchange nettyExchange, Exchange e) {
        return new SimpleDuplexExchange(nettyExchange, e, this.scheduler);
    }
}
